package club.xinghe.servlet.admin;

import club.xinghe.biz.StudentBiz;
import club.xinghe.entity.Student;
import club.xinghe.util.JsonServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/StudentPageServlet")
public class StudentPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentBiz studentBiz=new StudentBiz ();
        int countSize=studentBiz.getCountStudent ();
        int currPage= Integer.parseInt ( request.getParameter ( "currpage" ) );
        int pageSize= Integer.parseInt ( request.getParameter ( "pagesize" ) );

        int countPages=studentBiz.countPages ( countSize,pageSize );

        List<Student>studentList=studentBiz.selectStudentByMap ( currPage,pageSize );

        Map<String,Object>map=new HashMap<> (  );
        map.put ( "currPage",currPage );
        map.put ( "countPages",countPages );
        map.put ( "studentList",studentList );
        JsonServlet.getJson ( request,response,map );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost ( request, response );
    }
}
